//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.xxxy.jsq.action.distrib;

import com.alibaba.fastjson2.JSONObject;
import com.xxxy.jsq.dao.DistribDao;
import com.xxxy.jsq.model.Distrib;
import com.xxxy.jsq.model.Page;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet({"/getAllDistribsPageServlet"})
public class getAllDistribsPageServlet extends HttpServlet {
    public getAllDistribsPageServlet() {
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        Distrib model = new Distrib();
        DistribDao dao = new DistribDao();
        Page page = new Page();
        if (request.getParameter("roleId") != null && !request.getParameter("roleId").isEmpty()) {
            model.setRoleId(Long.parseLong(request.getParameter("roleId")));
        }

        if (request.getParameter("distribFlag") != null && !request.getParameter("distribFlag").isEmpty()) {
            model.setDistribFlag(request.getParameter("distribFlag"));
        }

        if (request.getParameter("page") != null && request.getParameter("limit") != null) {
            page.setCurrentPage(Integer.parseInt(request.getParameter("page")));
            page.setCount(Integer.parseInt(request.getParameter("limit")));
        }

        List<Distrib> list = dao.getAllDataByPage(model, page);
        int total = dao.getCount(model);
        JSONObject jo = new JSONObject();
        jo.put("code", 0);
        jo.put("msg", "success");
        jo.put("count", total);
        jo.put("data", list);
        PrintWriter out = response.getWriter();
        out.print(jo.toString());
        out.flush();
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        this.doPost(request, response);
    }
}

